/**
 * login
 * @author Brant Liu
 * @email lbf1988@qq.com
 * @date 2019/9/26
 * @version 1.0.0
 */
layui.extend({setter: 'setter'}).define(['jquery', 'form', 'layer', 'setter', 'validate'], function(exports){
    "use strict";
    var $ = layui.jquery, form = layui.form, layer = layui.layer, setter = layui.setter;

    var ELEM_FORM = '#login-form', ELEM_SUBMIT = '.btn-submit';

    var _e = {};

    _e.version = "1.0.0";

    var _option = $.extend({}, setter.validate, {
        rules: {
            username: {
                required: true,
                rangelength: [5, 30]
            },
            password: {
                required: true,
                rangelength: [6, 30]
            },
            captcha: {
                required: true
            }
        },
        messages: {
            username: {
                required: "请输入登录账号",
                rangelength: "请输入长度在 {0} 到 {1} 之间的字符串"
            },
            password: {
                required: "请输入登录密码",
                rangelength: "请输入长度在 {0} 到 {1} 之间的字符串"
            },
            captcha: {
                required: "请输入验证码"
            }
        },
        submitHandler: function(_form){
            console.log(_form);
        }
    });

    var _handler = function(){
        $(ELEM_FORM).validate(_option);
    };

    $(document).ready(function(){
        var _submit = $(ELEM_SUBMIT);
        _submit.removeAttr('disabled');
        _submit.attr('type', 'submit');

        _handler();
    });

    exports('login', _e);
});